#Requires AutoHotkey v2.0

MyGui := Gui()
MyGui.Title := "Win快速跳转工具  v1.3.3  by谪仙"
MyGui.OnEvent("Close", (*) => ExitApp()) ; 主窗口关闭时结束脚本


tab := MyGui.Add("Tab3", , ["快速功能", "优化"])
tab.UseTab(1)
{
    ; 第一行
    icon := MyGui.Add("Picture", "w24 h24 Icon" 1, ".\icon\1.ico")
    devmgmt := MyGui.Add("Button", "x+5 yp w90", "设备管理器")
    devmgmt.OnEvent("Click", (*) => Run("devmgmt.msc"))

    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\2.ico")
    printer := MyGui.Add("Button", "x+5 yp w90", "打印机") ; x+5表示在前一个控件右侧10像素，yp保持同一行
    printer.OnEvent("Click", (*) => Run("ms-settings:printers"))

    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\4.ico")
    CredentialManager := MyGui.Add("Button", "x+5 yp w90", "凭据管理器")
    CredentialManager.OnEvent("Click", (*) => Run("control /name Microsoft.CredentialManager"))

    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\5.ico")
    windowsdefender := MyGui.Add("Button", "x+5 yp w90", "安全中心")
    windowsdefender.OnEvent("Click", (*) => Run("ms-settings:windowsdefender"))

    ; 新一行
    ; 网络适配器
    icon := MyGui.Add("Picture", "x25 y+10 w24 h24 Icon" 1, ".\icon\31.ico")
    ncpa := MyGui.Add("Button", "x+5 w90", "网络适配器")
    ncpa.OnEvent("Click", (*) => Run("ncpa.cpl"))

    ; 设置-网络
    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\6.ico")
    network := MyGui.Add("Button", "x+5 yp w90", "设置-网络")
    network.OnEvent("Click", (*) => Run("ms-settings:network-status"))

    ; 网络工具
    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\45.ico")
    ipinfo := MyGui.Add("Button", "x+5 yp w90", ">网络工具")
    ipinfo.OnEvent("Click", GetIPInfo)

    ; 飞行模式
    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\47.ico")
    flymode := MyGui.Add("Button", "x+5 yp w90", "飞行模式")
    flymode.OnEvent("Click", (*) => Run("ms-settings:proximity"))

    ; 新一行
    icon := MyGui.Add("Picture", "x25 y+10 w24 h24 Icon" 1, ".\icon\25.ico")
    fsmgmt := MyGui.Add("Button", "x+5 yp w90", "共享管理")
    fsmgmt.OnEvent("Click", (*) => Run("fsmgmt.msc"))

    ; 本地共享
    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\7.ico")
    localshare := MyGui.Add("Button", "x+5 yp w90", "本地共享")
    localshare.OnEvent("Click", (*) => Run("\\localhost"))

    ; 访问共享
    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\43.ico")
    shared := MyGui.Add("Button", "x+5 yp w90", "访问共享")
    shared.OnEvent("Click", ToShared)

    ; 断开共享访问
    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\46.ico")
    delNetUse := MyGui.Add("Button", "x+5 yp w90", "断开共享访问")
    ; delNetUse.OnEvent("Click", (*) => Run("net use * /del"))
    delNetUse.OnEvent("Click", delNetUseF)

    ; 新一行
    icon := MyGui.Add("Picture", "x25 y+10 w24 h24 Icon" 1, ".\icon\8.ico")
    controlpanel := MyGui.Add("Button", "x+5 yp w90", "控制面板")
    controlpanel.OnEvent("Click", (*) => Run("control.exe"))

    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\23.ico")
    regedit := MyGui.Add("Button", "x+5 yp w90", "注册表编辑器")
    regedit.OnEvent("Click", (*) => Run("regedit"))

    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\24.ico")
    services := MyGui.Add("Button", "x+5 yp w90", "服务")
    services.OnEvent("Click", (*) => Run("services.msc"))

    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\26.ico")
    taskmgr := MyGui.Add("Button", "x+5 yp w90", "任务管理器")
    taskmgr.OnEvent("Click", (*) => Run("taskmgr"))

    ; 新一行
    icon := MyGui.Add("Picture", "x25 y+10 w24 h24 Icon" 1, ".\icon\事件查看器.ico")
    eventvwr := MyGui.Add("Button", "x+5 w90", "事件查看器")
    eventvwr.OnEvent("Click", (*) => Run("eventvwr.msc"))

    ; 资源监视器
    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\29.ico")
    resourcemonitor := MyGui.Add("Button", "x+5 yp w90", "资源监视器")
    resourcemonitor.OnEvent("Click", (*) => Run("Resmon"))
    ; resourcemonitor.OnEvent("Click", (*) => Run("perfmon.exe /res"))

    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\9.ico")
    sysprops := MyGui.Add("Button", "x+5 yp w90", "系统属性")
    sysprops.OnEvent("Click", (*) => Run("sysdm.cpl"))

    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\13.ico")
    sysabout := MyGui.Add("Button", "x+5 yp w90", "关于Windows")
    sysabout.OnEvent("Click", (*) => Run("ms-settings:about"))

    ; 新一行
    icon := MyGui.Add("Picture", "x25 y+10 w24 h24 Icon" 1, ".\icon\37.ico")
    OptionalFeatures := MyGui.Add("Button", "x+5 w90", "可选功能")
    OptionalFeatures.OnEvent("Click", (*) => Run("ms-settings:optionalfeatures"))

    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\18.ico")
    FeaturesMgr := MyGui.Add("Button", "x+5 yp w90", "Windows功能")
    FeaturesMgrFile := "C:\Windows\System32\OptionalFeatures.exe"
    if FileExist(FeaturesMgrFile) {
        FeaturesMgr.OnEvent("Click", (*) => Run(FeaturesMgrFile))
    } else {
        FeaturesMgrFile := "C:\Windows\SysNative\OptionalFeatures.exe"
        if FileExist(FeaturesMgrFile) {
            FeaturesMgr.OnEvent("Click", (*) => Run(FeaturesMgrFile))
        } else {
            MsgBox("OptionalFeatures.exe在系统目录中不存在")
        }
    }

    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\19.ico")
    appwiz := MyGui.Add("Button", "x+5 yp w90", "程序")
    appwiz.OnEvent("Click", (*) => Run("appwiz.cpl"))

    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\21.ico")
    defaultapps := MyGui.Add("Button", "x+5 yp w90", "默认应用")
    defaultapps.OnEvent("Click", (*) => Run("ms-settings:defaultapps"))

    ; 新一行
    icon := MyGui.Add("Picture", "x25 y+10 w24 h24 Icon" 1, ".\icon\20.ico")
    startupapps := MyGui.Add("Button", "x+5 w90", "启动项")
    startupapps.OnEvent("Click", (*) => Run("ms-settings:startupapps"))

    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\16.ico")
    lusrmgr := MyGui.Add("Button", "x+5 yp w90", "本地用户和组")
    lusrmgr.OnEvent("Click", (*) => Run("lusrmgr.msc"))

    ; 任务计划程序
    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\任务计划.ico")
    taskschd := MyGui.Add("Button", "x+5 yp w90", "任务计划程序")
    taskschd.OnEvent("Click", (*) => Run("taskschd.msc"))

    ; 防火墙
    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\30.ico")
    firewall := MyGui.Add("Button", "x+5 yp w90", "防火墙")
    firewall.OnEvent("Click", (*) => Run("firewall.cpl"))

    ; 新一行
    ; 修复
    icon := MyGui.Add("Picture", "x25 y+10 w24 h24 Icon" 1, ".\icon\15.ico")
    recovery := MyGui.Add("Button", "x+5 w90", "系统修复")
    recovery.OnEvent("Click", (*) => Run("sfc /scannow"))

    ; 检查磁盘错误
    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\22.ico")
    chkdsk := MyGui.Add("Button", "x+5 yp w90", "磁盘检查修复")
    chkdsk.OnEvent("Click", DiskCheck)

    ; 用户账户控制
    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\38.ico")
    uac := MyGui.Add("Button", "x+5 yp w90", "用户账户控制")
    uac.OnEvent("Click", (*) => Run("UserAccountControlSettings"))

    ; 存储
    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\39.ico")
    stormgmt := MyGui.Add("Button", "x+5 yp w90", "存储管理")
    stormgmt.OnEvent("Click", (*) => Run("ms-settings:storagesense"))

    ; 新一行
    ; 清理图标缓存
    icon := MyGui.Add("Picture", "x25 y+10 w24 h24 Icon" 1, ".\icon\14.ico")
    delIconCache := MyGui.Add("Button", "x+5 w90", "清理图标缓存")
    delIconCache.OnEvent("Click", DelIconCacheF)

    ; 清理temp目录
    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\14.ico")
    delTemp := MyGui.Add("Button", "x+5 yp w90", "清理temp目录")
    delTemp.OnEvent("Click", DelTempF)

    ; 组策略
    icon := MyGui.Add("Picture", "x+5 yp w24 h20 Icon" 1, ".\icon\41.ico")
    gpedit := MyGui.Add("Button", "x+5 yp w90", "组策略")
    gpedit.OnEvent("Click", (*) => Run("gpedit.msc"))

    ; secpol.msc
    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\48.ico")
    secpol := MyGui.Add("Button", "x+5 yp w90", "安全策略")
    secpol.OnEvent("Click", (*) => Run("secpol.msc"))

    ; 新一行
    ; Edge配置清空
    icon := MyGui.Add("Picture", "x25 y+10 w24 h24 Icon" 1, ".\icon\44.ico")
    edgeX := MyGui.Add("Button", "x+5 yp w90", "Edge配置清空")
    edgeX.OnEvent("Click", EdgeConfigClear)


    ; 重启资源管理器
    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, "C:\Windows\explorer.exe")
    restartExplorer := MyGui.Add("Button", "x+5 yp w90", "重启资源管理器")
    ; restartExplorer.OnEvent("Click", (*) => Run('powershell -Command "Get-Process explorer | Stop-Process -Force"'))
    ; restartExplorer.OnEvent("Click", (*) => Run('cmd.exe /c taskkill /f /im explorer.exe & start explorer.exe'))
    restartExplorer.OnEvent("Click", (*) => Run('powershell Stop-Process -Name "explorer" -Force'))

    ; 屏幕键盘
    icon := MyGui.Add("Picture", "x+5 yp w24 h24 Icon" 1, ".\icon\42.ico")
    keyboard := MyGui.Add("Button", "x+5 yp w90", "屏幕键盘")
    keyboard.OnEvent("Click", (*) => Run("osk"))

    ; 电源
    icon := MyGui.Add("Picture", "x+5 w24 h24 Icon" 1, ".\icon\49.ico")
    power := MyGui.Add("Button", "x+5 yp w90", ">电源")
    power.OnEvent("Click", PowerF)

}

tab.UseTab(2)
{
    ; 关闭系统预留空间
    btclosespace := MyGui.Add("Button", "x20 y35 ", "关闭系统预留空间")
    btclosespace.OnEvent("Click", (*) => Run("DISM /Online /Set-ReservedStorageState /State:Disabled"))

    ; 关闭BitLocker加密
    btclosebitlocker := MyGui.Add("Button", "x+5 yp ", "关闭BitLocker加密")
    btclosebitlocker.OnEvent("Click", closebitlockerF)

    ; 禁用sysMain
    btsysMain := MyGui.Add("Button", "x+5 yp ", "禁用sysMain")
    btsysMain.OnEvent("Click", DisSysMain)

    ; 禁用Windows Search 服务
    btsearch := MyGui.Add("Button", "x+5 yp ", "禁用Windows Search")
    btsearch.OnEvent("Click", (*) => Run("sc stop WSearch"))

    ; 解除程序文件风险警告
    btProgramWarning := MyGui.Add("Button", "x20 y+5", "解除程序文件风险警告")
    btProgramWarning.OnEvent("Click", (*) => Run('reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Associations" /v "ModRiskFileTypes" /t REG_SZ /d ".bat;.exe;.reg;.vbs;.chm;.msi;.js;.cmd" /f'))





}

MyGui.Show()
; ==============================================
DisSysMain(*) {
    RunWait("sc stop SysMain")
    RunWait("sc config SysMain start= disabled")
}

closebitlockerF(*) {
    ; 获取所有盘符
    drives := DriveGetList()
    ; 遍历每个盘符
    loop parse drives {
        RunWait("manage-bde -off " A_LoopField ":")
    }
}


GetIPInfo(*) {
    ; MsgBox(RunCmd("ipconfig"), "IP信息", "OK 4096")
    MyGui := Gui()
    MyGui.Title := "IP信息"

    ; 添加 Edit 控件，设置宽度和高度，显示多行文本
    EditCtrl := MyGui.Add("Edit", "w600 h600 ReadOnly BackgroundFFFFFF", "")

    ; 添加关闭按钮，并设置为默认焦点
    BtnClose := MyGui.Add("Button", "w80 Default", "关闭")
    BtnClose.OnEvent("Click", (*) => MyGui.Destroy())

    ; 按钮，查看全部信息
    BtnShowAll := MyGui.Add("Button", "x+5 yp w80", "查看全部")
    BtnShowAll.OnEvent("Click", (*) => EditCtrl.Value := RunCmd("ipconfig /all"))

    ; 按钮，查看简约信息
    BtnShowSimple := MyGui.Add("Button", "x+5 yp w80", "简约信息")
    BtnShowSimple.OnEvent("Click", (*) => EditCtrl.Value := RunCmd("ipconfig"))

    ; 按钮，查看DNS缓存
    BtnShowDNS := MyGui.Add("Button", "x+5 yp w80", "DNS缓存")
    BtnShowDNS.OnEvent("Click", (*) => EditCtrl.Value := RunCmd("ipconfig /displaydns"))

    ; 按钮，查看ARP信息
    BtnShowDNS := MyGui.Add("Button", "x+5 yp w80", "ARP缓存")
    BtnShowDNS.OnEvent("Click", (*) => EditCtrl.Value := RunCmd("arp -a"))

    ; 按钮，查看路由表信息
    BtnShowRoute := MyGui.Add("Button", "x+5 yp w80", "路由表")
    BtnShowRoute.OnEvent("Click", (*) => EditCtrl.Value := RunCmd("route print"))

    ; 第二行
    ; 按钮，导出, 保存到txt文件，用户选择保存路径
    BtnExport := MyGui.Add("Button", "x10 y+5 w80", "导出")
    BtnExport.OnEvent("Click", (*) => ExportIPInfo(EditCtrl.Value))


    ; 按钮，查看端口
    BtnPort := MyGui.Add("Button", "x+5 yp w80", "查看端口")
    BtnPort.OnEvent("Click", (*) => EditCtrl.Value := RunCmd("netstat -ano"))

    ; 按钮，重置Winsock
    BtnResetWinsock := MyGui.Add("Button", "x+5 yp w80", "重置Winsock")
    BtnResetWinsock.OnEvent("Click", (*) => (RunCmd("netsh winsock reset"), EditCtrl.Value := "Winsock 已重置！"))

    ; 按钮，清除DNS缓存
    BtnFlushDNS := MyGui.Add("Button", "x+5 yp w80", "清除DNS缓存")
    BtnFlushDNS.OnEvent("Click", (*) => (RunCmd("ipconfig /flushdns"), EditCtrl.Value := "DNS 缓存已清除！"))

    ; 按钮，清除ARP缓存
    BtnFlushARP := MyGui.Add("Button", "x+5 yp w80", "清除ARP缓存")
    BtnFlushARP.OnEvent("Click", (*) => (RunCmd("arp -d"), EditCtrl.Value := "ARP缓存已清除！"))

    ; 按钮，清除路由表
    BtnFlushRoute := MyGui.Add("Button", "x+5 yp w80", "清除路由表")
    BtnFlushRoute.OnEvent("Click", (*) => (RunCmd("route -f"), EditCtrl.Value := "路由表已清除！"))


    ; 显示 GUI 时将焦点设置到按钮上
    MyGui.Show()
    EditCtrl.Value := RunCmd("ipconfig")
    BtnClose.Focus()  ; 设置焦点到关闭按钮
}

; 导出IP信息到txt文件, 保存到用户选择的路径
ExportIPInfo(txtinfo) {
    ; 检查输入内容是否为空
    if (txtinfo = "") {
        MsgBox("没有可导出的内容！", "提示", "OK Icon!")
        return
    }

    ; 使用 FileSelect 打开保存文件对话框
    ; S16: 保存对话框，带覆盖确认
    ; 默认路径为桌面，默认文件名包含时间戳
    filePath := FileSelect("S16", A_Desktop "\IP信息_" . FormatTime(A_Now, "yyyyMMdd_HHmmss") . ".txt",
        "保存 IP 信息", "文本文件 (*.txt)")

    ; 如果用户取消保存操作，则退出
    if (filePath = "") {
        return
    }

    ; 尝试写入文件并处理可能的错误
    try {
        ; "w" 模式表示写入（覆盖现有文件）
        file := FileOpen(filePath, "w")
        file.Write(txtinfo)
        file.Close()  ; 关闭文件句柄
        ; MsgBox("导出成功！文件已保存到:`n" . filePath, "成功", "OK Iconi")
        Run(filePath)  ; 打开导出的文件
    } catch as err {
        MsgBox("导出失败！错误信息: " . err.Message, "错误", "OK Icon!")
    }
}

; 执行cmd命令并获取结果
RunCmd(command) {
    ; 创建 GUI 显示“正在获取数据，请等待...”
    guiWait := Gui("+AlwaysOnTop -SysMenu")  ; 创建一个置顶、无系统菜单的窗口
    guiWait.Title := "请稍候"  ; 设置窗口标题
    guiWait.Add("Text", , "正在执行命令，请等待...")
    guiWait.Show("xCenter yCenter")  ; 显示在屏幕中央

    ; 执行命令
    shell := ComObject("WScript.Shell")
    exec := shell.Exec(A_ComSpec " /c " command)
    result := exec.StdOut.ReadAll()

    ; 获取结果后销毁 GUI
    guiWait.Destroy()

    return result
}

; Edge配置清空函数
EdgeConfigClear(*) {
    Result := MsgBox("是否清空Edge配置？`nEdge浏览器的书签、保存密码、登录状态都将丢失！！！", "Edge配置清空", "OKCancel 4096")
    if (Result = "OK") {
        if (FileExist("%localappdata%\Microsoft\Edge\User Data")) {
            RunWait('cmd /c del /q "%localappdata%\Microsoft\Edge\User Data"')
            MsgBox("Edge配置已清空！", "Edge配置清空", "OK 4096")
        } else {
            MsgBox("Edge配置已清空！", "Edge配置清空", "OK 4096")
        }
    }

}

; 访问共享
ToShared(*) {
    ToSharedGui := Gui()
    ToSharedGui.Title := "访问共享"
    ToSharedGui.Add("Text", , "请输入共享路径:")
    sharePath := ToSharedGui.Add("Edit", "w110", "\\192.168.")
    okButton := ToSharedGui.Add("Button", "w80", "确定")
    ; okButton.OnEvent("Click", (*) => Run("explorer " sharePath.Text))
    okButton.OnEvent("Click", (*) => startToShare(sharePath.Text))
    ToSharedGui.Show()
}
; 打开共享目录
startToShare(url) {
    if (url == "" or url == "\\192.168.") {
        MsgBox("请输入共享路径！", "访问共享", "OK 4096")
        return
    } else {
        Run("explorer " url)
    }
}


; 清理temp目录
DelTempF(*) {
    RunWait('cmd /c del /q "%temp%\*"')
    RunWait('cmd /c for /d %i in (%temp%\*) do rd /s /q "%i"')
    MsgBox("temp目录已清理！", "清理temp目录工具", "OK 4096")
}

; 清理图标缓存
DelIconCacheF(*) {
    RunWait('cmd /c del /q "%localappdata%\Microsoft\Windows\Explorer\*"')
    RunWait('powershell -Command "Get-Process explorer | Stop-Process -Force"')
    ; Run('explorer')
    MsgBox("图标缓存已清理！", "清理图标缓存工具", "OK 4096")
}

; 按钮点击事件处理函数
DiskCheck(*) {
    ; 获取所有盘符
    drives := DriveGetList()

    ; 创建选择盘符的 GUI
    driveGui := Gui()
    driveGui.Title := "选择盘符"
    driveGui.Add("Text", , "请选择一个盘符进行检查:")

    ; 添加下拉列表
    driveList := driveGui.Add("DropDownList", "w100")

    ; 将盘符字符串拆分为单个字符并添加到下拉列表
    driveList.Add(StrSplit(drives))

    ; 添加确定按钮
    okButton := driveGui.Add("Button", "w80", "确定")
    okButton.OnEvent("Click", OkButtonClick)

    ; 显示选择盘符的 GUI
    driveGui.Show()

    ; 确定按钮点击事件处理函数
    OkButtonClick(*) {
        ; 获取选择的盘符
        selectedDrive := driveList.Text
        if selectedDrive == "" {
            MsgBox("请选择一个盘符！", "磁盘检查工具", "OK 4096")
            return
        }

        ; 关闭选择盘符的 GUI
        driveGui.Destroy()

        ; 执行 chkdsk 命令
        RunWait("chkdsk " selectedDrive ": /f")

        ; 提示用户检查完成
        MsgBox("磁盘检查已完成！", "磁盘检查工具", "OK 4096")
    }
}

delNetUseF(*) {
    RunWait('cmd /c net use * /del /y')
    RunWait('cmd /c klist purge')
    MsgBox("网络连接已删除！`n但会话缓存可能仍会持续数分钟！", "删除网络连接", "OK 4096")
}
PowerF(*) {
    powerGui := Gui("+AlwaysOnTop")
    powerGui.Title := "电源管理"
    ; 电源选项
    powercfgcpl := powerGui.Add("Button", "x+5 yp w90", "电源选项")
    powercfgcpl.OnEvent("Click", (*) => Run("powercfg.cpl"))
    ; 电源设置
    powercfg := powerGui.Add("Button", "x+5 yp w90", "电源设置")
    powercfg.OnEvent("Click", (*) => Run("ms-settings:powersleep"))
    ; 新一行
    ; 快速启动开关
    GroupBoxQuickStart := powerGui.Add("GroupBox", "x10 y30 w90 h50 Section", "快速启动")
    quickStart := powerGui.Add("Button", "xs+5 ys+18 w35", "开")
    quickStart.OnEvent("Click", (*) => quickStartF("on"))
    quickStartoff := powerGui.Add("Button", "xs+50 ys+18 w35", "关")
    quickStartoff.OnEvent("Click", (*) => quickStartF("off"))

    ; 休眠开关
    GroupBoxSleep := powerGui.Add("GroupBox", "x110 y30 w90 h50 Section", "休眠")
    hibernate := powerGui.Add("Button", "xs+5 ys+18 w35", "开")
    hibernate.OnEvent("Click", (*) => hibernateSwitchF("on"))
    hibernateoff := powerGui.Add("Button", "xs+50 ys+18 w35", "关")
    hibernateoff.OnEvent("Click", (*) => hibernateSwitchF("off"))


    powerGui.Show()
}
quickStartF(flag) {
    if (flag = "on") {
        ExitCode := RunWait('cmd /c reg add "HKLM\SYSTEM\ControlSet001\Control\Session Manager\Power" /v "HiberbootEnabled" /t REG_DWORD /d "1" /f')
        if (ExitCode != 0) {
            MsgBox("快速启动开启失败！退出代码: " . ExitCode, "电源管理", "OK 4096")
        }
    } else {
        ExitCode := RunWait('reg add "HKLM\SYSTEM\ControlSet001\Control\Session Manager\Power" /v "HiberbootEnabled" /t REG_DWORD /d "0" /f')
        if (ExitCode != 0) {
            MsgBox("快速启动关闭失败！退出代码: " . ExitCode, "电源管理", "OK 4096")
        }
    }
}
hibernateSwitchF(flag) {
    if (flag = "on") {
        ExitCode := RunWait('powercfg /h on')
        if (ExitCode != 0) {
            MsgBox("休眠开启失败！退出代码: " . ExitCode, "电源管理", "OK 4096")
        }
    } else if (flag = "off") {
        ExitCode := RunWait('powercfg /h off')
        if (ExitCode != 0) {
            MsgBox("休眠关闭失败！退出代码: " . ExitCode, "电源管理", "OK 4096")
        }
    }
}